
var Update = {
	subSys:'',
	updateID:'',
	formTable:null,
	pDialog:null,
	form:null,
	
	init:function(){
		if(funcUrl==""){
			System.showError('错误', "系统错误：报表功能edit的类型为用户自定义，必须提供功能URL!");
			top.$.messager.progress('close');
			return;
		}
		var subSys = System.getRequest("subSys",funcUrl);
		var updateID = System.getRequest("updateID",funcUrl);
		var dlgId = System.getRequest("dlgId",location.href);
		
		top.$.messager.progress('close');
		if(!subSys||!(updateID)){
			System.showError('错误', "系统错误：修改URL中必须提供subSys及updateID参数值!");
			return;
		}
		Update.subSys = subSys;
		Update.updateID = updateID;
		if(dlgId){
			Update.pDialog = System.getCache(dlgId);
		}
		if(!Update.pageInfo()){
			return;
		}
		Update.initPage();
		Update.initForm();
	},
	pageInfo:function(){
		var url = System.getRootPath()+"/"+funcUrl;
		var result = false;
		System.ajaxGet(url,function(data){
			if(data.result=='error'){
				System.showError('错误', data.message);
				result = false;
			}else{
				Update.subSys = data.subSys;
				Update.updateID = data.updateId;
				Update.formTable = data.formTable;
				result = true;
			}
		},false);
		return result;
	},
	initPage:function(){
		if(!Update.formTable){
			return;
		}
		var pageTitle = Update.formTable.ftName;
		Update.pDialog.dialog('setTitle',pageTitle);
	},
	initForm:function(){
		var _formId = 'updForm';
		Update.createForm(_formId);
		Form.formId = _formId;
		Form.formType = 'upd';
		var formTables = new Array(1);
		formTables[0] = Update.formTable;
		Form.formTables = formTables;
		Form.init();
		Update.initFun();
	},
	createForm:function(formId){
		var _formHtml = "<form id=\""+formId+"\" method=\"post\">";
		_formHtml += "<table class=\"formTable\" width=\"100%\">";
		_formHtml += "</table></form>";
		$('div.easyui-layout').layout('panel','center').html(_formHtml);
		Update.form = $('form');
	},
	initFun:function(){
		var _funArea = "<div style=\"text-align: center; padding: 5px;\">";
		_funArea += "<a id=\"btnEp\" class=\"easyui-linkbutton\" icon=\"icon-ok\" href=\"javascript:Update.submit();\" >保存</a> ";
		_funArea += "<a id=\"btnCancel\" class=\"easyui-linkbutton\" icon=\"icon-cancel\" href=\"javascript:Update.closeWin();\">关闭</a>";
		_funArea += "</div>";
		$('div.easyui-layout').layout('add',{    
			region: 'south',    
			border:false,
			content:_funArea,
			height:40
		});
	},
	closeWin:function(){
		if(Update.pDialog){
			Update.pDialog.dialog('close');
		}
	},
	submit:function(){
		var url = System.getRootPath()+'/sysmng.update.do?subSys='+Update.subSys+"&updateID="+Update.updateID;
		Update.form.form('submit', {
			url: url,
			onSubmit: function () {
				var validateResult = $(this).form('validate');
				return validateResult;
			},
			success: function (data) {
				eval('data=' + data);
				if(data.result=="error"){
					System.showError('错误', data.msg);
					result = false;
					return;
				}
				if (data.result) {
					var sourceObj = Update.pDialog.sourceObj;
					if(sourceObj){
						sourceObj.grid.datagrid('reload');
					}
					Update.closeWin();
				} else {
					$.messager.alert('错误', data.msg, 'error');
				}
			}
		});
	}
}